package com.jfinal.weixin.demo.xingshi;

import com.alibaba.fastjson.JSON;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

/**
 * http://avatardata.cn/Docs/Api/7fd9b74b-f051-4751-9f9e-26da8bcc674e
 * Created by wangxiaoyang on 16/8/28.
 */
public class XingshiApi {

    private static final String baseUrl = "http://api.avatardata.cn/XingShiQiYuan/LookUp?key=3bae84be966b46dcb1b91a997d758ed2&xingshi=";

    public static void main(String[] args) {
        getXingshi(new OkHttpClient(),"汪");
    }

    public static XingshiBean getXingshi(OkHttpClient httpClient , String xingshi) {
        String url = baseUrl + xingshi;
        Request request = new Request.Builder()
                .url(url)
                .build();
        try {
            Response response = httpClient.newCall(request).execute();
            String resule = response.body().string();
            System.out.println(resule);
            XingshiBean xingshiBean = JSON.parseObject(resule,XingshiBean.class);
            System.out.println(xingshiBean.format());
            return xingshiBean;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
